﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class SliderChange : MonoBehaviour, IPointerUpHandler
{
    Slider slider;
    // Start is called before the first frame update
    void Start()
    {
        slider = this.GetComponent<Slider>();
        slider.value = Manage.instance.old_index;
        slider.GetComponentInChildren<Text>().text = (Manage.instance.old_index - 3).ToString();
        slider.onValueChanged.AddListener(
            (value) => {
                Manage.instance.SetSoundActive((int)value);
                SetSliderText((int)value);
                Vibrate();
            }
            );
    }

    void SetSliderText(int index)
    {
        slider.GetComponentInChildren<Text>().text = (index - 3).ToString();
    }
    void Vibrate()
    {
        GameFunction.Vibrate(GameData.sliderVibrateIndex);
    }
    void AutoReturn()
    {
        if (slider.value != 3)
            slider.value = 3;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        if (GameData.autoReturn == true)
            AutoReturn();
    }
}
